package com.joven.shelltest.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: wzj
 * @Date: 2024/1/31 15:17
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {

    @Bean("jovenThreadPool")
    public ThreadPoolExecutor myThreadPool(){
        return new ThreadPoolExecutor(
                //核心数，一直都能工作的数量
                2,
                //请求处理大时，可以开放的最大工作数
                5,
                //开启最大工作数后，当无请求时，还让其存活的时间
                3,
                //存活时间单位
                TimeUnit.SECONDS,
                //阻塞队列，保存操作请求线程
                new LinkedBlockingDeque<>(10),
                //创建线程的工厂类
                Executors.defaultThreadFactory(),
                //拒绝策略
                new ThreadPoolExecutor.AbortPolicy());
    }


}
